﻿@model string
<div class="current-location hidden">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">字段管理</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="main">
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head form-inline form-group-sm">
        <tr>
            <td>
                <div class="btn-group">
                    <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                    <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                        菜单
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li>
                            <a href="javascript:void(0)" class="ui-dialog" data-custom-params="title:'添加字段',url:'@Url.Action("Add",new {tableName=Request.QueryString["tableName"],area="admin"})',width:'95%',height:'95%'">添加</a>
                        </li>
                        @*<li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-updateMultiple" data-custom-params="url:'@Url.ActionUrl("UpdateList")',callBack:'LoadData'">更新</a></li>*@
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.ActionUrl("Delete")',beforeExecute:'BeforeDelete',callBack:'LoadData'">删除</a></li>
                    </ul>
                </div>
            </td>
            <td align="right">
                <select id="searchfield"  name="searchfield" class="form-control ui-queryString ui-setName">
                    <option value="name">按字段搜索</option>
                    <option value="remark">按标识搜索</option>
                </select>
                <input type="text" id="name" name="name" maxlength="19" class="form-control ui-keyword ui-queryString" style="width:100px;">
                <input type="button" value="确定" class="btn btn-default btn-sm ui-queryString-search">
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered form-inline form-group-sm" id="tb_list">
        <thead>
            <tr>
                <td align="center" style="width:40px" rowspan="2"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align="center" rowspan="2">字段</td>
                <td align="center" rowspan="2">备注</td>
                <td align="center" rowspan="2">值类型</td>
                <td align="center" rowspan="2">字段类型</td>
                <td align="center" colspan="2">后台发布项</td>
                <td align="center" colspan="2">会员发布项</td>
                <td align="center" colspan="1">匿名投稿项</td>
                <td align="center" colspan="2">管理列表</td>
                <td align="center" colspan="2">模板页面</td>
                <td align="center" rowspan="2">系统字段</td>
                <td align="center" rowspan="2">序号</td>
                <td align="center" rowspan="2">附表字段</td>
                <td align="center" rowspan="2">管理</td>
            </tr>
            <tr>
                <td align="center" colspan="2">添加页/编辑页</td>
                <td align="center" colspan="2">添加页/编辑页</td>
                <td align="center" colspan="1">可发布</td>
                <td align="center">后台</td>
                <td align="center">会员</td>
                <td align="center">列表读取</td>
                <td align="center">内容读取</td>
            </tr>
        </thead>

        <tr class="item" id="item_{id}" sysField="{sysField}">
            <td align="center"><input type="checkbox" class="checked-item" value="{id}"></td>
            <td align="center"><span class="sp_name">{name}</span></td>
            <td align="center">{remark}</td>
            <td align="center"><span class="sp_valueType{valueType}">{valueType}</span></td>
            <td align="center"><span class="lb_fieldType" data-fieldChildType="{fieldChildType}">{fieldType}</span></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="AdminCanAdd" name="AdminCanAdd" value="1" /></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="AdminCanEdit" name="AdminCanEdit" value="1" /></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="MemberCanAdd" name="MemberCanAdd" value="1" /></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="MemberCanEdit" name="MemberCanEdit" value="1" /></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="AnonymousCanAdd" name="AnonymousCanAdd" value="1" /></td>
            @*<td align="center"><input class="set-item" type="checkbox" id="AnonymousCanEdit" name="AnonymousCanEdit" value="1" /></td>*@
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="AdminListItem" name="AdminListItem" value="1" /></td>
            <td align="center"><input class="set-item" data-id="{id}" type="checkbox" id="MemberListItem" name="MemberListItem" value="1" /></td>

            <td align="center"><input class="set-item"  data-id="{id}" type="checkbox" id="ListItem" name="ListItem" value="1" /></td>
            <td align="center"><input class="set-item"  data-id="{id}" type="checkbox" id="DetailItem" name="DetailItem" value="1" /></td>
            <td align="center"><span class="is-{sysField}"></span></td>
            <td align="center">
                <input type="text" name="Xuhao" id="Xuhao" readonly class="form-control ui-listXuhao" value='{xuhao}' data-table="pa_field" data-id="{id}" style="width:50px" maxlength="3" />
            </td>
            <td align="center">
                <button type="button" data-custom-params="title:'{name}-附属表字段管理',url:'@Url.ActionUrl("Index","Field")?tableName={tableName}_{name}',width:'95%',height:'95%'" class="btn btn-default btn-sm ui-dialog btn-filed-{fieldType}" disabled>管理</button>
            </td>
            <td align="center">
                <input type="hidden" name="id" value="{id}" />
                <div class="btn-group btn-group-sm">
                    <button type="button" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'修改字段-{remark}',url:'@Url.ActionUrl("Edit")?id={id}',width:'95%',height:'95%'">修改</button>

                    <button type="button" class="btn btn-default btn-sm ui-deleteSingle ui-deleteSingle-{sysField}" data-custom-params="url:'@Url.ActionUrl("Delete")',callBack:'LoadData'">删除</button>
                </div>
            </td>
        </tr>
</table>
</div>
<script type="text/javascript">

    var fieldExtend = { text: "单行文本", password: "密码文本", hidden: "隐藏域表单", select: "下拉表单",radio: "单选框", checkbox: "复选框", textarea: "多行文本", editor: "编辑器", image: "图片", images: "图片组", file: "附件", files: "附件组", subtable: "附属表" }

    function LoadData()
    {
        $("#tb_list").ListBind({url:"@Url.ActionUrl("ListData")?tableName=@Request.QueryString["tableName"]",callBack: "LoadedInit",formBind:true});
    }
    function LoadedInit()
    {
        var $btnFiledSubtable = $(".btn-filed-subtable");
        var $sp_sys_field = $(".sp_sys_field");
        var $sp_name = $(".sp_name");
        $sp_name.each(function () {
            var $this = $(this);
            if ($this.html() == "_custom_attribute") {
                //$this.html("系统字段")
            }
        });
        var $sp_valueType = $(".sp_valueType");
        $sp_valueType.text("/");
        var $lb_fieldType = $(".lb_fieldType");
        $lb_fieldType.each(function () {
            var $this = $(this);
            var dataFieldChildType = $this.attr("data-fieldChildType");
            var fieldType = $this.html();
            var val = eval("fieldExtend." + fieldType);
            $this.html(val);
        });
        $(".ui-deleteSingle-1").attr("disabled", "disabled");
        $btnFiledSubtable.removeAttr("disabled");
        RegIiemClick();
    }
    LoadData();


    function DelCallBack(id) {
        $("#item_" + id).hide();
    }

    function BeforeDelete(ids) {
        var arrIds = ids.split(",")
        for (i = 0; i < arrIds.length; i++) {
            if ($("#item_" + arrIds[i]).attr("sysField") == "1") {
                Alert("系统字段不能删除，请重新选择！");
                return false;
            }
        }
        return true;
    }


    function RegIiemClick()
    {
        $setItem=$(".set-item");
        $setItem.off("click").on("click", function () {
            var $this = $(this);
            var itemValue = 0;
            var field = $this.attr("id");
            var fieldId = $this.attr("data-id");
            if ($this.prop("checked"))
            {
                itemValue = 1;
            }
            var options = { url: "@Url.ActionUrl("UpdateItem")", type: "post", dataType:"html",data: { fieldId: fieldId, field: field, fieldValue: itemValue }};
            Ajax(options, function () {}, function (xhr, textStatus) { alert(textStatus) });
        });
    }

</script>

